package com.zkyc.framework.website.controller;

import com.zkyc.framework.common.Enum.LogType;
import com.zkyc.framework.common.annotation.Log;
import com.zkyc.framework.common.exception.ResultCode;
import com.zkyc.framework.common.pojo.PublicityMeeting;
import com.zkyc.framework.common.vo.ResultVO;
import com.zkyc.framework.website.service.PublicityMeetingService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * (PublicityMeeting)表控制层
 *
 * @author libingchuan
 * @since 2022-10-10 15:36:04
 */
@RestController
@RequestMapping("publicityMeeting")
public class PublicityMeetingController {
    /**
     * 服务对象
     */
    @Resource
    private PublicityMeetingService publicityMeetingService;
    
    /**
     * 查询
     *
     * @return 查询结果
     */
    @GetMapping("list")
    public ResultVO queryList() {
        return publicityMeetingService.queryList();
    }

    /**
     * 分页查询宣讲会
     *
     * @return 查询结果
     */
    @GetMapping("listByPage")
    public ResultVO listByPage(Integer current, Integer size) {
        return publicityMeetingService.listByPage(current,size);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("query/{id}")
    public ResultVO queryById(@PathVariable("id") Integer id) {
        PublicityMeeting publicityMeeting = publicityMeetingService.queryById(id);
        if(publicityMeeting == null){
            return ResultVO.fail(ResultCode.SERVE_ERROR);
        }
        return ResultVO.data(publicityMeeting);
    }

    /**
     * 新增数据
     *
     * @param publicityMeeting 实体
     * @return 新增结果
     */
    @PostMapping("save")
    @Log(type= LogType.新增招聘宣讲)
    public ResultVO add(@RequestBody PublicityMeeting publicityMeeting) {
        return publicityMeetingService.insert(publicityMeeting);
    }

    /**
     * 编辑数据
     *
     * @param publicityMeeting 实体
     * @return 编辑结果
     */
    @PostMapping("edit")
    @Log(type= LogType.编辑招聘宣讲)
    public ResultVO edit(@RequestBody PublicityMeeting publicityMeeting) {
        return publicityMeetingService.update(publicityMeeting);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("delete")
    public ResultVO deleteById(Integer id) {
        return publicityMeetingService.deleteById(id);
    }

    @PostMapping("upOrDown")
    public ResultVO upOrDown(@RequestBody PublicityMeeting meeting) {
        return publicityMeetingService.upOrDown(meeting);
    }
}

